/*******************************************************************************
 * Copyright (c) 2004, 2005 Jean-Michel Lemieux, Jeff McAffer and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Hyperbola is an RCP application developed for the book
 *     Eclipse Rich Client Platform -
 *         Designing, Coding, and Packaging Java Applications
 *         (http://eclipsercp.org)
 * Contributors:
 *     Jean-Michel Lemieux and Jeff McAffer - initial implementation
 *******************************************************************************/
package org.reliablesource.prism.product.workbench;

import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class PrismWorkbenchAdvisor extends WorkbenchAdvisor {

    /**
     * Whether to show non-rectangular windows.
     */
    private boolean useNonRect = false;
    
    /**
     * Support for showing a custom background jobs indicator and status messages.
     */
    public static final String PROGRESS_PROVIDER_KEY = "progress_provider";
//	private StatusLineProgressProvider statusLineProgressProvider;
        
	public void preStartup() {
//		statusLineProgressProvider = new StatusLineProgressProvider();
//		Platform.getJobManager().setProgressProvider(statusLineProgressProvider);
	}

	public void initialize(IWorkbenchConfigurer configurer) {
		super.initialize(configurer);
        
        // process command line args
        List args = Arrays.asList(Platform.getApplicationArgs());
        useNonRect = args.contains("-nonRect");
        
        // have the workbench save its layout between sessions
		configurer.setSaveAndRestore(true);
        
        // See bug 73795 - no programmatic way of setting the active key configuration
        // TODO: use ui .ini file instead
//        ((MutableCommandManager) PlatformUI.getWorkbench().getCommandSupport().getCommandManager()).setActiveKeyConfigurationId("org.eclipsercp.hyperbola.ui.commands.keyConfiguration");       
	}
	
    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
            IWorkbenchWindowConfigurer configurer) {
        if (useNonRect) {
            return new PrismNonRectWorkbenchWindowAdvisor(configurer);
        }
//        configurer.setData(PROGRESS_PROVIDER_KEY, statusLineProgressProvider);
        return new PrismWorkbenchWindowAdvisor(configurer);
    }

	public String getInitialWindowPerspectiveId() {
        return DefaultPerspective.ID;
	}
	
}
